package servlet;

import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/jstl")
public class JstlServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String[] arr = {"lisi", "wangwu"};
        req.setAttribute("arr",arr);
        Map<String, Object> map = new HashMap<>();
        map.put("map1", "li");
        map.put("map2", "wang");
        req.setAttribute("map",map);

        List<User> users = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            users.add(new User(i, "username" + i, "password" + i));
        }
        req.setAttribute("users",users);
        req.getRequestDispatcher("jstl.jsp").forward(req, resp);
    }
}
